<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>基础设置-项目构成</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>项目构成</span></div>
<div id="qForm"  class="mini-toolbar1" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <div class="mb-20 position-rel">
                    <span class="search-title">区域</span>
                    <div id="areaItem" class="area"></div>
                    <span class="search-title search-ml60">项目名称</span><input id = "itemName" name="itemName" class="mini-textbox search-200px"   value="">
                    <a class="add-botton search-ml60" onclick="list.search()">查询</a>
                    <a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
                </div>
            </td>
        </tr>
    </table>
</div>
<div class="container">
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-6">
            <a class="plan-btn mR-20"  onclick="list.addOrEditGroups('new')"><span class="add-bg"></span>新增组团</a>
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增期区</a>
            <a class="plan-btn mR-20"  onclick="list.addOrEditBuilding('new')"><span class="add-bg"></span>新增楼栋</a>
        </div>
    </div>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-treegrid" style="width:100%;height:100%;" url="/tree/itemInfo/list" dataField="data"
         treeColumn="name" showTreeIcon="true" treeColumn="no" idField="id" parentField="pid" resultAsTree="false"
         allowResize="true" expandOnLoad="true" allowSortColumn="false" sortMode="client">
        <div property="columns">
            <!--<div type="checkcolumn" headerAlign="center" align="center"></div>-->
            <div type="indexcolumn" headerAlign="center" align="center">编号</div>
            <div name="name" field="name" width="200" headerAlign="center" allowSort="false">项目/组团/期区/楼栋</div>
            <!--<div field="createName" width="120" headerAlign="center" allowSort="false">备注</div>-->
            <div field="createName" width="200" headerAlign="center" align="center" allowSort="false">创建人</div>
            <div field="createDate" width="200" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">创建时间</div>
            <div name="action" width="200" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //list.init();
    var grid;
    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            common.areaItem.init({idName:'#areaItem'});
            grid = mini.get("datagrid1");
            grid.load();
            list.gridFilter();
            
            grid.on("drawcell", function (e) {
                var column = e.column;
                if (column.name == "action") {
                    if(e.row.type!="item"){
                        if(e.row.status==0){
                            e.cellHtml = '<a class="revise-botton" href="javascript:list.subOredit(\''+'edit'+'\')">编辑</a><a class="check-botton btn-bd" href="javascript:list.view()">查看</a><a class="del-botton btn-bd" onclick="list.remove()">删除</a>';
                        }else{
                            e.cellHtml = '<a class="revise-botton" href="javascript:list.subOredit(\''+'edit'+'\')">编辑</a><a class="check-botton btn-bd" href="javascript:list.view()">查看</a>';
                        }
                    }else {
                        e.cellHtml = '<a class="check-botton" href="javascript:list.view()">查看</a>';
                    }
                }
            })
        },
        //隐藏item下面的为空的
        gridFilter:function(){
        	 grid.filter(function(row){
             	if(row.type=="item"){
             		if(row.status==0){
             			return false;
             		}else{
                 		return true;
                 	}
             	}else{
             		return true;
             	}
             });
             
        },
        //    新增或编辑楼栋
        addOrEdit: function (opt) {
            mini.open({
                url: "/dataBase/project/new.html",
                title: (opt=="edit"?"编辑":"新增")+"期区", width: 1100, height: 550,
                onload: function () {
                    if(opt=="edit"){
                        var row = grid.getSelected();
                        var id = row.id.substr(0,row.id.lastIndexOf("@"));
                        var data = {"id": id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                    list.gridFilter();
                }
            });
        },
        addOrEditGroups: function(opt){
            mini.open({
                url: "/dataBase/project/newGroups.html",
                title: (opt=="edit"?"编辑":"新增")+"组团", width: 1100, height: 400,
                onload: function () {
                    if(opt=="edit"){
                        var row = grid.getSelected();
                        var id = row.id.substr(0,row.id.lastIndexOf("@"));
                        var data = {"id": id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                    list.gridFilter();
                }
            });
        },
        subOredit:function(opt){
            var row = grid.getSelected();
            if(row.type =="group"){
                list.addOrEditGroups(opt);
            }else if(row.type =="phase"){
                list.addOrEdit(opt);
            }else if(row.type =="build"){
                list.addOrEditBuilding(opt);
            }
        },
        addOrEditBuilding: function(opt){
            mini.open({
                url: "/dataBase/project/newBuilding.html",
                title: (opt=="edit"?"编辑":"新增")+"楼栋", width: 1100, height: 500,
                onload: function () {
                    if(opt=="edit"){
                        var row = grid.getSelected();
                        var id = row.id.substr(0,row.id.lastIndexOf("@"));
                        var data = {"id": id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                    list.gridFilter();
                }
            });
        },
        //    查看
        view: function(){
            var row = grid.getSelected();
            var subUrl,height;
            if(row.type=='item'){
                subUrl = '/dataBase/itemInfo/view.html';
                height = 700;
            }else if(row.type =="group"){
                subUrl = '/dataBase/project/viewGroups.html';
                height = 400;
            }else if(row.type =="phase"){
                subUrl = '/dataBase/project/view.html';
                height = 550;
            }else if(row.type =="build"){
                subUrl = '/dataBase/project/viewBuilding.html';
                height = 500;
            }
            if (row) {
                mini.open({
                    url: subUrl,
                    title: "项目构成", width: 1100, height: height,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var id = row.id.substr(0,row.id.lastIndexOf("@"));
                        var data = {"id": id};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                        list.gridFilter();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var data = {
                "provinceId": mini.get("provinceCombo").getValue(),
                "cityId": mini.get("cityCombo").getValue(),
                "itemName": mini.get("itemName").getValue()
            };
            grid.load(data);
            list.gridFilter();
        },
        //重置
        reset:function(){
            var form = new mini.Form("qForm");
            form.reset();
            grid.load()
            list.gridFilter();
        },
        //    删除
        remove: function () {
            var row = grid.getSelected();
            var subUrl;
            if(row.type =="group"){
                subUrl = '/group/del';
            }else if(row.type =="phase"){
                subUrl = '/phase/del';
            }else if(row.type =="build"){
                subUrl = '/Building/del';
            }
            var id = row.id.substr(0,row.id.lastIndexOf("@"));
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: subUrl,
                            type : "post",
                            data:{"id":id},
                            success: function (text) {
                                if (text.state) {
                                    grid.reload();
                                    list.gridFilter();
                                } else {
                                    mini.showMessageBox({
                                        showModal: false,
                                        width: 250,
                                        title: "提示",
                                        iconCls: "mini-messagebox-warning",
                                        message: text.message,
                                    });

                                }
                            },
                            error:function (errorMsg) {
                                common.prompt(errorMsg.message);
                            }
                        });
                    }
                });
            } else {
                alert("请选中一条记录");
            }
        }
    };
    list.init();
</script>
</body>
</html>